package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.Task;
import com.sc.nft.mapper.TaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 任务表(sc_task)数据DAO
 *
 * @author 张翔宇
 * @since 2023-03-29 11:14:52
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class TaskDao extends ServiceImpl<TaskMapper, Task> {

    public Page<Task> taskPage(String name, Boolean status, Long daoId,int pageNo, int pageSize) {
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(name), Task::getTaskName, name);
        queryWrapper.eq(status != null, Task::getStatus, status);
        queryWrapper.eq( Task::getDaoId, 6L);
        queryWrapper.orderByDesc(Task::getId);
        return this.page(new Page<>(pageNo, pageSize), queryWrapper);
    }

    public Page<Task> taskMerchantPage(String name, Boolean status, Long daoId,int pageNo, int pageSize) {
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(name), Task::getTaskName, name);
        queryWrapper.eq(status != null, Task::getStatus, status);
        queryWrapper.eq(daoId != null, Task::getDaoId, daoId);
        queryWrapper.notIn(Task::getDaoId, 6L);
        queryWrapper.orderByDesc(Task::getId);
        return this.page(new Page<>(pageNo, pageSize), queryWrapper);
    }

    public List<Task> getTodayTask(Long daoId) {
        return baseMapper.getTodayTask(null,daoId);
    }

    public List<Task> getTodayMerchantTask() {
        return baseMapper.getTodayMerchantTask();
    }

    public List<Task> getTodayTask(Integer taskType) {
        return baseMapper.getTodayTask(taskType,null);
    }

    public List<Task> getByTaskName(String taskName){
        LambdaQueryWrapper<Task> query = new LambdaQueryWrapper<>();
        query.eq(Task::getIsDelete, Boolean.FALSE);
        query.like(Task::getTaskName, taskName);
        return baseMapper.selectList(query);
    }
}